local clsCallJavaStaticMethod = Class("lua/util/clsInstance.lua"):Inherit()

function clsCallJavaStaticMethod:New(...)
	return self
end

function clsCallJavaStaticMethod:checkArguments(args, sig)
    if type(args) ~= "table" then args = {} end
    if sig then return args, sig end

    sig = {"("}
    for i, v in ipairs(args) do
        local t = type(v)
        if t == "number" then
            sig[#sig + 1] = "F"
        elseif t == "boolean" then
            sig[#sig + 1] = "Z"
        elseif t == "function" then
            sig[#sig + 1] = "I"
        else
            sig[#sig + 1] = "Ljava/lang/String;"
        end
    end
    sig[#sig + 1] = ")V"

    return args, table.concat(sig)
end

function clsCallJavaStaticMethod:callStaticMethod(className, methodName, args, sig)
    local args, sig = self:checkArguments(args, sig)
	local callJavaStaticMethod = CCLuaJavaBridge.callStaticMethod
    local ok, ret = callJavaStaticMethod(className, methodName, args, sig)
	return ok,ret
end

function getClass()
	return clsCallJavaStaticMethod
end

--[[
local javaClassName = "org/cocos2dx/hellolua/HelloLua"
local javaMethodName = "showAlertDialog"
local javaParams = {
			"hello lua",
			"hi lua",
			function(event)
				print("Java method callback value is " .. tostring(event))
			end
		}
local javaMethodSig = "(Ljava/lang/String;Ljava/lang/String;I)V"
local luaj = Class("lua/util/clsCallJavaStaticMethod.lua"):getInstance()
luaj:callStaticMethod(javaClassName, javaMethodName, javaParams, javaMethodSig)
]]--
